import {all, call, put, take, fork} from 'redux-saga/effects';
import * as actions from './actions'
import * as constants from './actionTypes';
import {fetchDataApi} from '@/api';

function* fetchData(){
    yield put(actions.fetchDataRequest())
    try{
        const data = yield call(fetchDataApi)
        yield put(actions.fetchDataSuccess(data))
    }catch(error){
        yield put(actions.fetchDataFailure(error))
    }
}


export default function* watchIndexSaga(){
    while(true){
        yield take(constants.FETCH_DATA)
        yield fork(fetchData)
    }
}